import {
  HerinFind,
  HerinProject,
  HerinSort,
} from '../../types/type/request.type';
import { SortEnum } from './param.enum';

// 各种类型参数查询类型
export type ParamBaseType = string[] | string;
export type QueryParamType = QueryCondition[] | QueryCondition;

export type SortParam = ParamBaseType;
export type SearchParam = ParamBaseType;
export type MatchParam = ParamBaseType;
export type RangeParam = ParamBaseType;
export type EitherParam = ParamBaseType;
export type ProjectParam = ParamBaseType;
export type PageParam = string | number;

// query下的查询参数
export type QueryParam = {
  page?: PageParam; // 页码
  perpage?: PageParam; // 条数
  sort?: SortParam; // 排序
  search?: SearchParam; // 模糊搜索
  match?: MatchParam; // 直接匹配
  range?: RangeParam; // 范围搜索
  or?: EitherParam; // 或查询
  project?: ProjectParam; // 返回字段
  join?: string; // 新增字段，用于指定连表查询
  joinProject?: string; // 新增字段，用于指定连表查询中选择的字段
};

export type QueryBodyParam = {
  page?: PageParam; // 页码
  perpage?: PageParam; // 条数
  sort?: SortParam; // 排序
  search?: SearchParam; // 模糊搜索
  match?: QueryParamType; // 直接匹配
  range?: RangeParam; // 范围搜索
  or?: EitherParam; // 或查询
  project?: ProjectParam; // 返回字段
  join?: JoinParam; // 新增字段，用于指定连表查询
  joinProject?: string[]; // 新增字段，用于指定连表查询中选择的字段
  other: any; // 其他情况兼容
};

// 参数处理后返回结果
export type ParamHandle = {
  skip: number;
  limit: number;
  findObj?: HerinFind;
  project?: HerinProject;
  sort?: HerinSort;
};

export type QueryCondition = {
  column: string; // 字段名
  operator: string; // 比较标识符
  value: any; // 值
};

export type JoinParam = {
  from: string;
  localField: string;
  foreignField: string;
  as: string;
};

// 页码
export type PageStructure = { skip: number; limit: number };

// 排序传参规则
export type SortOptions = [string, SortEnum];
